<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
    <head>
        <title>Hyphenator.js &ndash; Test cp</title>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <style type="text/css">
            body {
                width:50%;
                margin-left:25%;
                margin-right:25%;
            }
            .test {
            	background-color: #ffd6d6;
            	text-align:justify;
            	width : 66%;
            }
            .ref {
            	background-color: #d6ffd6;
            }
            pre {
            	border: 1px dotted grey;
            }
            div {
                text-align:justify;
            }
        </style>
        <script type="text/javascript">var djConfig = {isDebug:true, parseOnLoad:true};</script>
        <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.4.0/dojo/dojo.xd.js" type="text/javascript"></script>
        <script src="../Hyphenator.js" type="text/javascript"></script>
        <script type="text/javascript">
			var hyphenatorSettings = {
				minwordlength: 4
			};
			Hyphenator.config(hyphenatorSettings);
			Hyphenator.run();
			
			var HYPHENATION = true;
			var TEXTSELECTION = ['', ''];
			
			function reHyphenate() {
				if (HYPHENATION === false) {
					Hyphenator.toggleHyphenation();
					HYPHENATION = true;
				}
			}
			
			function keyFF(e) {
				if (dojo.isFF && e.keyCode === 67) {
					reHyphenate();
				}
			}
			
			function analyzeSelection() {
				if (dojo.isIE && dojo.isIE > 4) {
					if (document.selection) {
						TEXTSELECTION[1] = document.selection.createRange().text;
					}
				} else { 
					TEXTSELECTION[1] = document.getSelection();
				}
				if (TEXTSELECTION[1] === TEXTSELECTION[0] || TEXTSELECTION[1]  === "") {
					reHyphenate();
				} 
			}
			
			dojo.connect(dojo.byId("myHyphenatedNodeID"), "onmousedown", function (e) {
				if (HYPHENATION === true) {
					Hyphenator.toggleHyphenation();
					HYPHENATION = false;
				}                                                                                                
			});
			
			dojo.connect(dojo.byId("myHyphenatedNodeID"), "onmouseup", "analyzeSelection");
			
			dojo.connect(dojo.byId("myBodyID"), "onkeypress", function (e) {
				if (e.charOrCode === dojo.keys.copyKey && e.charOrCode === 'c') {
					setTimeout(reHyphenate, 80);
				}
			});
			
			dojo.connect(window, "onblur", "reHyphenate");
        </script>
    </head>
    <body id="myBodyID" onkeydown="keyFF(event)";>
        <h1>copy&amp;paste test</h1>
        <p>Check if a <a href="http://code.google.com/p/hyphenator/issues/detail?id=34#c10">possible solution</a> provided by Sebastian Lasse works. Copy the red text (or a part of it) and paste it in the textarea:</p>
        <p class="hyphenate test" lang="en" id="myHyphenatedNodeID">To allow more efficient usage of paper, more regular appearance of right-side margins without requiring spacing adjustments, and to eliminate the need to erase hand-written long words begun near the end of a line that do not fit, words may be divided at the nearest breakpoint between syllables and a hyphen inserted to indicate that the letters form a word fragment, not a word.</p>
        <textarea cols="50" rows="10" class="ref"></textarea>
    </body>
</html>